<?php
include 'SocketTool.class.php';
include 'SwitchType.class.php';
include 'JsonAction.class.php';
include 'FileAction.class.php';
include 'Datas.object.php';
include 'Filter.class.php';
/*
*SwitchType 类负责根据get参数来动态实例化控制类型
*控制类型 Alones  Floors  Surroundings只负责根据命令返回格式化数据
*Sockettool类用于建立socke链接完成数据传输后然后关闭
*Json类用于json的相关操作
*/
if(isset($_GET['type'])){//组装get数据
    $arrayDate=array($_GET['type']);
    $key=$arrayDate[key($arrayDate)];
    unset($arrayDate[0]);
    if(isset($_GET['floor']) && $_GET['floor']>=0){
        $arrayDate[$key]['floor']=$_GET['floor'];
    }
    if(isset($_GET['number']) && $_GET['number']>=0){
        $arrayDate[$key]['number']=$_GET['number'];
    }
    if(!empty($_GET['static'])){
        if($_GET['static']=='on'){
            $arrayDate[$key]['static']='NO';
        }
        if($_GET['static']=='off'){
            $arrayDate[$key]['static']='NC';
        }
    }
}else{
    echo '参数有误';
    exit;
}
$jsonObject=JsonAction::Encode($arrayDate);//将接收到的json数据进行解析
$filerArray=Filter::Get('record.json',$jsonObject);
//建立socket链接并执行命令
$socket=new SocketTool();
$socketData=$socket ->openSocket();
foreach($filerArray as $k=>$v){
    $msg=$v.':'.str_replace('.',';',$k).'#';
    $socket->writeSocket($socketData,$msg);


}
$socket->closeSocket($socketData);
//FileAction::Write('test.json',$msg);

?>




